<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="${staticServer}/inc/style/main.css" />
<link rel="stylesheet" href="${staticServer}/inc/style/page.css" />
<link rel="stylesheet" href="${staticServer}/css/struct_info.css" />
<script src="${staticServer}/inc/js/jquery.js"></script>
<script src="${staticServer}/inc/js/pageset.js"></script>
<script src="${staticServer}/inc/js/submitter.js"></script>
<script src="${staticServer}/inc/js/infopad.js?2.2"></script>
<script type="text/javascript" src="${staticServer}/common/uploadify/jquery.uploadify.js"></script>
<script type="text/javascript" src="${staticServer}/js/web/uploadImg.js?1.5"></script>
	
<link rel="stylesheet" href="${staticServer}/inc/style/date/datepicker.css" />
<script src="${staticServer}/inc/js/datepicker.js"></script>

<style>
#SWFUpload_0{
	margin-top: 70px;
    margin-left: -30px;
}
#SWFUpload_1{
	margin-top: 70px;
    margin-left: -30px;
}
.SEARCH_hide h3 {
    overflow: hidden;
    height: 8px;
    line-height: 16px;
    color: #a6a6a6;
    font-weight: 400;
    font-size: 14px;
    padding: 8px 15px 10px 15px;
}
.SEARCH_hide {
    position: absolute;
    width: 238px;
    box-shadow: 0 2px 2px #e5e5e5;
    background-color: #fff;
    border: 1px solid #e5e5e5;
    z-index: 99;
}
.SEARCH_hideL {
    float: left;
    width: 238px;
    height: 400px;
    overflow: hidden;
    border-right: 1px solid #e5e5e5;
}
</style>
<script>
var contextPath='${contextPath}';
var _contextPath = '${staticServer}';

$(function(){
	var id = $("#id").val();
	if(id!=null&&id!=""){
		$("#jd_center_key").val("<#if invoice??>${invoice.jd_center_key}</#if>");
		$("#moneyType1").val("<#if invoice??>${invoice.moneyType1}</#if>");
		$("#moneyType2").val("<#if invoice??>${invoice.moneyType2}</#if>");
		$("#method").val("<#if invoice??>${invoice.method_id}</#if>");
		$("#is_otkj").val("<#if invoice??>${invoice.is_otkj}</#if>");
		$("#invoice_content").val("<#if invoice??>${invoice.invoice_content}</#if>");
		$("#is_opened").val("<#if invoice??>${invoice.is_opened}</#if>");
		$("#state").val("<#if invoice??>${invoice.state}</#if>");
		$("#is_urgent").val("<#if invoice??>${invoice.is_urgent}</#if>");
	}
	var keyname = $("#jd_center_key").val();
	if(keyname!=null && keyname!=""){
		$.post("${contextPath}/index/getMethod.json", {
			"keyname":keyname
		}, function(ms) {
			var list = ms.mList;
			var objHtml = '<option value="">请选择缴费类型</option>';
			for(var i=0;i<list.length;i++){
				if(list[i].name!="POS刷卡（备用）"){
					objHtml +='<option value="'+list[i].id+'">'+list[i].name+'</option>';
				}
			}
			$("#method").html('<select id="method_id" <#if flg=='view'> disabled</#if>>'+objHtml+'</select>');
			$("#method_id").val("<#if invoice??>${invoice.method_id}</#if>");
		});
		
	}
	
	$("#jd_center_key").change(function(){
		var keyname = $("#jd_center_key").val();
		$.post("${contextPath}/index/getMethod.json", {
			"keyname":keyname
		}, function(ms) {
			var list = ms.mList;
			var objHtml = '<option value="">请选择交款方式</option>';
			for(var i=0;i<list.length;i++){
				if(list[i].name!="POS刷卡（备用）"){
					objHtml +='<option value="'+list[i].id+'">'+list[i].name+'</option>';
				}
			}
			$("#method").html('<select id="method_id">'+objHtml+'</select>');
		});
	});
	
	$("#student").keyup(function(){
		var student = $("#student").val();
		$("#stu_id").val("");
		if(student!=null && student!=""){
			$.post("${contextPath}/index/getStudentByName.json", {
				"nickname":student
			}, function(ms) {
				var list = ms.list;
				var objHtml = '';
				for(var i=0;i<list.length;i++){
					objHtml +='<h3 onmouseover="getHtml('+list[i].id+',\''+list[i].nickname+'\')"><span class="historys">'+list[i].nickname+list[i].phone+'</span></h3>';
				}
				
				$("#SearchHide1").html('<div class="SEARCH_hideL">'+objHtml+'</div>');
				$("#SearchHide1").show();
			});
		}
	});
	
	$(document).click(function(){
		$("#SearchHide1").hide();
    
    	$("#xltype").click(function(event){
			event.stopPropagation();
		});
	});
});

var getHtml = function(id,nickname){
	$("#student").val(nickname);
	$("#stu_id").val(id);
}

var save = function(){
	var id = $("#id").val();
	var stu_id = $("#stu_id").val();
	var jd_center_key = $("#jd_center_key").val();
	var student = $("#student").val();
	var moneyDate = $("#moneyDate").val();
	var moneyType1 = $("#moneyType1").val();
	var moneyType2 = $("#moneyType2").val();
	var method_id = $("#method_id").val();
	var moneys = $("#moneys").val();
	var methodNote = $("#methodNote").val();
	var courseSituation = $("#courseSituation").val();
	var first_trainDate = $("#first_trainDate").val();
	var train_teacher = $("#train_teacher").val();
	var is_otkj = $("#is_otkj").val();
	var is_urgent = $("#is_urgent").val();
	var is_urgentnote = $("#is_urgentnote").val();
	var invoice_content = $("#invoice_content").val();
	var invoice = $("#invoice").val();
	var is_opened = $("#is_opened").val();
	var taxpayerNumber = $("#taxpayerNumber").val();
	var openBank = $("#openBank").val();
	var account = $("#account").val();
	var address = $("#address").val();
	var phone = $("#phone").val();
	var invoice_Amount = $("#invoice_Amount").val();
	var openedAccount = $("#openedAccount").val();
	var traceAccount = $("#traceAccount").val();
	var post_Address = $("#post_Address").val();
	var beizhu = $("#beizhu").val();
	
	if(jd_center_key==""){
		infopad.err("请选择接待中心!");
		return;
	}
	if(method_id==""){
		infopad.err("请选择交款方式!");
		return;
	}
	if(invoice==""){
		infopad.err("开票抬头不能为空!");
		return;
	}
	if(taxpayerNumber==""){
		infopad.err("纳税人识别号不能为空!");
		return;
	}
	if(openBank==""){
		infopad.err("开户行号不能为空!");
		return;
	}
	if(account==""){
		infopad.err("账号不能为空!");
		return;
	}
	if(address==""){
		infopad.err("地址不能为空!");
		return;
	}
	if(phone==""){
		infopad.err("电话不能为空!");
		return;
	}
	if(invoice_Amount==""){
		infopad.err("开票金额不能为空!");
		return;
	}
	
	$.post("${contextPath}/index/save_Apply_Invoice.json", {
			"id":id,
			"stu_id":stu_id,
			"jd_center_key":jd_center_key,
			"student":student,
			"moneyDate":moneyDate,
			"moneyType1":moneyType1,
			"moneyType2":moneyType2,
			"method_id":method_id,
			"moneys":moneys,
			"methodNote":methodNote,
			"courseSituation":courseSituation,
			"first_trainDate":first_trainDate,
			"train_teacher":train_teacher,
			"is_otkj":is_otkj,
			"is_urgent":is_urgent,
			"is_urgentnote":is_urgentnote,
			"invoice_content":invoice_content,
			"invoice":invoice,
			"is_opened":is_opened,
			"taxpayerNumber":taxpayerNumber,
			"openBank":openBank,
			"account":account,
			"address":address,
			"phone":phone,
			"invoice_Amount":invoice_Amount,
			"openedAccount":openedAccount,
			"traceAccount":traceAccount,
			"post_Address":post_Address,
			"beizhu":beizhu
		}, function(ms) {
		    var msg = ms.msg;
		    if(msg!=null && msg=="1"){
				infopad.msg("操作成功！");
				window.location.href="${contextPath}/index/invoiceList.htm";
		    }else if(msg=="0"){
		    	infopad.err("已审核，不可编辑！");
		    }else{
		    	infopad.err("操作失败，请联系管理员！");
		    }
	});
	
};
var updateInvoiceState = function(){
	var id = $("#id").val();
	var state = $("#state").val();

	if(state=="" || state=="0"){
		infopad.err("请选择审核状态!");
		return;
	}
	
	$.post("${contextPath}/index/updateInvoiceState.json", {
			"id":id,
			"state":state
		}, function(ms) {
		    var msg = ms.msg;
		    if(msg!=null && msg=="1"){
				infopad.msg("操作成功！");
				window.location.href="${contextPath}/index/invoiceList.htm";
		    }else{
		    	infopad.err("操作失败，请联系管理员！");
		    }
			
	});
}

</script>
</head>
<input type="hidden" id="id" value="<#if invoice??>${invoice.id}</#if>">
<input type="hidden" id="stu_id" value="<#if invoice??>${invoice.stu_id}</#if>">
<body>
	<div id="home_link">
		<ul>
			<li></li>
			<li>&gt;</li>
			<li>组织架构</li>
			<li>&gt;</li>
			<li class="current">添加发票申请 </li>
			<li></li>
		</ul>
	</div>

	<div id="container">
		<table id="infotable">
			<tr>
				<th>学员训练中心:<span style="color:#ff2122;">*</span></th>
				<td>
				<select id="jd_center_key" <#if flg=='view'> disabled</#if> >
					<option value="">请选择中心</option>
					<#if office_List??>
						<#list office_List as list>
							<option value="${list.keyname}">${list.name}</option>
						</#list>
					</#if>
				</select>
				</td>
			
			</tr>
			<tr>
				<th>学生姓名:</th>
				<td style="text-align:left; padding-left:10px; line-height:20px;">
				<input type="text" id="student" value="<#if invoice??>${invoice.student}</#if>" class="input" <#if flg=='view'> disabled</#if>><span style="font-size:10px; margin-left:5px; color:#b04b87;">*<font color="red">
				1.输入准确的学生姓名，在下来框选择，系统设置无法手动录入2.下拉框中如无缴费学员姓名，咨询老师填写学员信息后方可选择</font></span>
                     <div class="SEARCH_hide" style="display: none;" id="SearchHide1">
                          <div class="SEARCH_hideL">
                          </div>
                     </div>  
				</td>
			</tr>
			<tr>
				<th>缴费日期:</th>
				<td style="height:20px;">
					<input type="text" id="moneyDate" value="<#if invoice??>${invoice.moneyDate?date}</#if>" <#if flg=='view'> disabled</#if> rel="DATE::Y-m-d" value="" size="15" maxlength="15" readonly="readonly" class="DatePicker_Icon">
				</td>
			</tr>
			<tr>
				<th>缴费类型:</th>
				<td>
					<select id="moneyType1" <#if flg=='view'> disabled</#if>>
						<option value="">缴费类别</option>
						<option value="1">新增</option>
						<option value="2">续费</option>
					</select>
					<select id="moneyType2" <#if flg=='view'> disabled</#if>>
						<option value="">缴费类型</option>
						<option value="1">定金</option>
						<option value="2">部分款</option>
						<option value="3">全款</option>
						<option value="4">尾款</option>
					</select>
					</td>
			</tr>
			<tr>
				<th>交款方式/金额:</th>
				<td>
					<span id="method">
					</span>
					缴费金额：<input id="moneys" type="text" value="<#if invoice??>${invoice.moneys}</#if>" <#if flg=='view'> disabled</#if>  onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')" onafterpaste="this.value=this.value.replace(/[^0-9.]/g,'')" size="10" maxlength="30" />元，
					
					<input id="methodNote" placeholder="交款备注" type="text" size="46" maxlength="100" value="<#if invoice??>${invoice.methodNote}</#if>" <#if flg=='view'> disabled</#if>/>
				</td>
			</tr>
			
			<tr>
				<th>报名课程情况:</th>
				<td>
					<input id="courseSituation" type="text" size="20" maxlength="100" value="<#if invoice??>${invoice.courseSituation}</#if>" <#if flg=='view'> disabled</#if>/>
				</td>
			</tr>
			<tr>
				<th>首次训练时间:</th>
				<td style="height:20px;">
					<input type="text" id="first_trainDate" rel="DATE::Y-m-d" value="<#if invoice??>${invoice.first_trainDate}</#if>" size="15" maxlength="15" readonly="readonly" class="DatePicker_Icon" <#if flg=='view'> disabled</#if>>
				</td>
			</tr>
			<tr>
				<th>训练老师:</th>
				<td>
					<input id="train_teacher" type="text" placeholder="学员的训练导师" value="<#if invoice??>${invoice.train_teacher}</#if>" size="46" maxlength="100" <#if flg=='view'> disabled</#if>/>
				</td>
			</tr>
			<tr>
				<th>是否同意开具其他地区的税务发票:</th>
				<td style="height:20px;">
					<select id="is_otkj" <#if flg=='view'> disabled</#if>>
						<option value="">请选择</option>
						<option value="0">否</option>
						<option value="1">是</option>
					</select>
					<#if webutil.getCookieUser().username=="xuetingting">
						<#if invoice??&&invoice.is_otkj=="0">
							<input id="opened_Center" type="text"  value="<#if center??>${center}</#if>" size="46" maxlength="100" <#if flg=='view'> disabled</#if>/>
						</#if>
					<#else>
						<span style="color:#ff2122;">（如杭州地区家长是否可以开具上海分公司抬头的发票）</span>
					</#if>
				</td>
			</tr>
			<tr>
				<th>是否紧急:</th>
				<td style="height:20px;">
					<select id="is_urgent" <#if flg=='view'> disabled</#if>>
						<option value="">请选择</option>
						<option value="0">否</option>
						<option value="1">是</option>
					</select>
					<input  id="is_urgentnote" type="text"  placeholder="如紧急，请备注原因"  value="<#if invoice??>${invoice.is_urgentnote}</#if>" size="46" maxlength="100" <#if flg=='view'> disabled</#if>/>
				</td>
			</tr>
			<tr>
				<th>开票内容:</th>
				<td style="height:20px;">
					<select id="invoice_content" <#if flg=='view'> disabled</#if>>
						<option value="">请选择</option>
						<option value="0">培训费</option>
						<option value="1">咨询费</option>
						<option value="2">服务费</option>
					</select>
				</td>
			</tr>
			<tr>
				<th>开票抬头:<span style="color:#ff2122;">*</span></th>
				<td style="height:20px;">
				<input id="invoice" type="text"  placeholder="如若是个人，需备注是开具“个人”2字样的，还是“XXX”学员名字样的"  size="80" maxlength="100" value="<#if invoice??>${invoice.invoice}</#if>" <#if flg=='view'> disabled</#if>>
				</td>
			</tr>
			<tr>
				<th>纳税人识别号:<span style="color:#ff2122;">*</span></th>
				<td>
					<input id="taxpayerNumber" type="text" size="46" maxlength="100" value="<#if invoice??>${invoice.taxpayerNumber}</#if>" <#if flg=='view'> disabled</#if>/>
				</td>
			</tr>
			<tr>
				<th>开户行:<span style="color:#ff2122;">*</span></th>
				<td>
					<input id="openBank" type="text" size="46" maxlength="100" value="<#if invoice??>${invoice.openBank}</#if>" <#if flg=='view'> disabled</#if>/>
				</td>
			</tr>
			<tr>
				<th>账号:<span style="color:#ff2122;">*</span></th>
				<td>
					<input id="account" type="text"  size="46" maxlength="100" value="<#if invoice??>${invoice.account}</#if>" <#if flg=='view'> disabled</#if>/>
				</td>
			</tr>
			<tr>
				<th>地址:<span style="color:#ff2122;">*</span></th>
				<td>
					<input id="address" type="text" size="46" maxlength="100" value="<#if invoice??>${invoice.address}</#if>" <#if flg=='view'> disabled</#if>/>
				</td>
			</tr>
			<tr>
				<th>电话:<span style="color:#ff2122;">*</span></th>
				<td>
					<input id="phone" type="text" size="46" maxlength="100" value="<#if invoice??>${invoice.phone}</#if>" <#if flg=='view'> disabled</#if>/>
				</td>
			</tr>
			<tr>
				<th>开票金额:<span style="color:#ff2122;">*</span></th>
				<td>
					<input id="invoice_Amount" type="text" size="46" maxlength="100" value="<#if invoice??>${invoice.invoice_Amount}</#if>" <#if flg=='view'> disabled</#if>/>
				</td>
			</tr>
			<tr>
				<th>是否已开过:</th>
				<td>
					<select id="is_opened" <#if flg=='view'> disabled</#if>>
						<option value="">请选择</option>
						<option value="0">是</option>
						<option value="1">否</option>
					</select>
					<span style="color:#ff2122;">之前是否已开过（续费的需备注之前开的金额）</span>
				</td>
			</tr>
			<tr>
				<th>已开具金额:</th>
				<td>
					<input id="openedAccount" type="text"  size="46" maxlength="100" value="<#if invoice??>${invoice.openedAccount}</#if>" <#if flg=='view'> disabled</#if>/>
				</td>
			</tr>
			<tr>
				<th>剩余开票金额:</th>
				<td>
					<input id="traceAccount" type="text"  size="46" maxlength="100" value="<#if invoice??>${invoice.traceAccount}</#if>" <#if flg=='view'> disabled</#if>/>
				</td>
			</tr>
			<tr>
				<th>邮寄地址:</th>
				<td>
					<input id="post_Address" type="text"  size="46" maxlength="100" value="<#if invoice??>${invoice.post_Address}</#if>" <#if flg=='view'> disabled</#if>/>
				</td>
			</tr>
			<tr>
				<th>备注:</th>
				<td>
					<textarea style="width:400px;height:80px;" type="text"  id="beizhu" <#if flg=='view'> disabled</#if>><#if invoice??>${invoice.beizhu}</#if></textarea>
				</td>
			</tr>
			<#if flg??&&flg=="view"&&webutil.getCookieUser().username=="xuetingting">
				<tr>
					<th>审核状态:</th>
					<td style="height:20px;">
						<select id="state">
							<option value="">请选择</option>
							<option value="0">未审核</option>
							<option value="1">未通过</option>
							<option value="2">已通过</option>
						</select>
					</td>
					</td>
				</tr>
			</#if>
		</table>
		<div id="controlbar">
		<#if flg??&&flg=="view"&&webutil.getCookieUser().username=="xuetingting">
			<input align="center" type="button" class="submit" onclick="updateInvoiceState()" value="  保  存  " />
		<#elseif flg??&&flg=="save">
			<input align="center" type="button" class="submit" onclick="save()" value="  保  存  " />
		<#elseif flg??&&flg=="edit">
			<input align="center" type="button" class="submit" onclick="save()" value="  保  存  " />
		</#if>
			<input align="center" type="button" class="submit" onclick="javascript:history.back()" value="  返回列表  " />
		</div>
	</div>
	
</body>
</html>